home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 6.4 KB | 284 lines | [TEXT/MPS ] |
- // UErrorMgr.cp
- // Copyright © 1984-1991 by Apple Computer Inc. All rights reserved.
-
-
- #ifndef __UERRORMGR__
- #include <UErrorMgr.h>
- #endif
-
- #ifndef __STDIO__
- #include <StdIo.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __UFAILURE__
- #include <UFailure.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- #ifndef __UMENUMGR__
- #include <UMenuMgr.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- //--------------------------------------------------------------------------------------------------
- Str255 gErrorParm3;
- ProcPtr gMacAppAlertFilter;
- Boolean gInFilter;
- Boolean gInhibitNestedHandling;
-
- //--------------------------------------------------------------------------------------------------
- struct ErrRecord
- {
- short lowErr, highErr, index;
- };
-
-
- typedef ErrRecord* ErrRecordPointer;
- typedef ErrRecordPointer* ErrRecordHandle;
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAError
-
- pascal void ErrorAlert(OSErr err,
- long message)
- {
- union Converter
- {
- struct
- {
- short hiWd, loWd;
- } shortVal;
- long message;
- };
-
-
- const long kMsgCmdErr = msgCmdErr / 0x10000;
- const long kMsgAlert = msgAlert / 0x10000;
- const long kMsgLookup = msgLookup / 0x10000;
- const long kMsgAltRecov = msgAltRecovery / 0x10000;
-
- Converter c;
- short alertID = phGenError; // the default alert
- Boolean genericAlert = TRUE;
- Str255 opString = "";
- Str255 errStr;
- OSErr recovErr;
- Str255 recovery;
-
- c.message = message;
-
- switch (c.shortVal.hiWd)
- {
- case kMsgCmdErr:
- alertID = phCmdErr;
- CmdToName(c.shortVal.loWd, opString);
- break;
-
- case kMsgAlert:
- alertID = c.shortVal.loWd;
- genericAlert = FALSE;
- break;
-
- case kMsgLookup:
- case kMsgAltRecov:
- LookupErrString(c.shortVal.loWd, errOperationsID, opString);
- break;
-
- default:
- GetIndString(opString, c.shortVal.hiWd, c.shortVal.loWd);
- break;
- }
-
- if (genericAlert)
- {
- LookupErrString(err, errReasonID, errStr);
-
- if (c.shortVal.hiWd == kMsgAltRecov)
- recovErr = c.shortVal.loWd;
- else
- recovErr = err;
-
- LookupErrString(recovErr, errRecoveryID, recovery);
-
- ParamText(errStr, recovery, opString, gErrorParm3);
-
- if (opString.IsEmpty())
- alertID = phUnknownErr;
- }
-
- StdAlert(alertID);
- gInhibitNestedHandling = FALSE; // Used suppress nested event handling
-
- if (genericAlert)
- ResetAlrtStage();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAError
-
- // Private function
- pascal Boolean SearchErrTable(short value,
- short resourceID,
- Str255& str)
- {
- ErrRecordHandle table;
-
- str = "";
- table = (ErrRecordHandle)GetResource('errs', resourceID);
- if (table)
- {
- short lenTab;
- short strID = 0;
- ErrRecordPointer pEntry = *table;
-
- lenTab = (short)(GetHandleSize((Handle)table) / sizeof(ErrRecord));
- for (short i = 1; i <= lenTab; ++i, ++pEntry)
- {
- if (pEntry->lowErr == 0)
- strID = pEntry->index;
- else if ((pEntry->lowErr <= value) && (value <= pEntry->highErr))
- {
- if (pEntry->index > 0)
- GetIndString(str, strID, pEntry->index);
- return TRUE;
- }
- }
- }
- return FALSE;
- }
-
-
- pascal Boolean LookupErrString(short value,
- short resourceID,
- Str255& str)
- {
- if (SearchErrTable(value, errAppTable + resourceID, str))
- return TRUE;
- else
- return SearchErrTable(value, resourceID, str);
- }
-
- //--------------------------------------------------------------------------------------------------
- /*$MC68020-*/ /* Need to be able to alert user if this
- isn't a 68020 machine */
- #pragma segment MAGlobalsRes
- // Don't require a segment load for this
-
- pascal void StdAlert(short alertID)
- {
- MacAppAlert(alertID, NULL);
- }
-
- //--------------------------------------------------------------------------------------------------
- /*$MC68020-*/ /* Need to be able to alert user if this
- isn't a 68020 machine, alert filter won't
- be installed until after that, though. */
- #pragma segment MAGlobalsRes
- // Don't require a segment load for this
-
- pascal short MacAppAlert(short alertID,
- ProcPtr filterProc)
- {
- AlertTHndl alrtTemplate;
- Boolean canAlert;
- SignedByte savedState;
- short alertReturn;
-
- #if qDebug
- gRsrcCheck = 0; // force immediate check.
- #endif
-
- SetCursor(qd.arrow);
- alrtTemplate = (AlertTHndl)GetResource('ALRT', alertID);
- if (!alrtTemplate)
- {
- #if qDebug
- Str255 theString;
- ConcatNumber("Unable to find or load ‘ALRT’ resource ", alertID, theString);
- ProgramBreak(theString);
- #endif
-
- SysBeep(2); // At least give some indication
- return 1; // Arbitrary result
- }
-
- if (!GetResource('DITL', (*alrtTemplate)->itemsID))// preflight the DITL
- {
- #if qDebug
- Str255 theString;
- ConcatNumber("Unable to find or load ‘DITL’ resource ", alertID, theString);
- ProgramBreak(theString);
- #endif
-
- SysBeep(2); // At least give some indication
- return 1; // Arbitrary result
- }
-
- CouldAlert(alertID);
- canAlert = (ResError() == noErr) && (MemError() == noErr);
- FreeAlert(alertID);
- if (!canAlert)
- {
- #if qDebug
- Str255 theString;
- ConcatNumber("Unable to display alert ", alertID, theString);
- ProgramBreak(theString);
- #endif
-
- SysBeep(2); // At least give some indication
- return 1; // Arbitrary result
- }
-
- // Success at last!
- savedState = LockHandleHigh((Handle)alrtTemplate);
-
- // Only center the ALRT if not on System 7, otherwise assume that the bit is set
- // in the ALRT template in order to do the centering.
- if (!(qNeedsSystem7 || gConfiguration.systemVersion >= 0x700))
- CenterRectOnScreen((*alrtTemplate)->boundsRect, TRUE, TRUE, TRUE);
-
- PullApplicationToFront(); // !!! hmmm...do we need this on System 7
-
- if (!filterProc)
- alertReturn = Alert(alertID, (ModalFilterProcPtr)gMacAppAlertFilter);
- else
- alertReturn = Alert(alertID, (ModalFilterProcPtr)filterProc);
-
- // restore the state of the DITL's handle
- HSetState((Handle)alrtTemplate, savedState);
- return alertReturn;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAError
-
- #if qDebug
- pascal void NotYetImplemented(const Str255& where)
- #else
- pascal void NotYetImplemented(const Str255& /* where */)
- #endif
-
- {
- #if qDebugMsg
- fprintf(stderr, "NotYetImplemented: %s\n", (char *) where);
- #endif
-
- Failure(errNotImplemented, 0);
- }
-
-
-